home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / Kubuntu 8.10 / kubuntu-8.10-desktop-i386.iso / casper / filesystem.squashfs / etc / init.d / urandom < prev    next >
Text File  |  2008-10-14  |  2KB  |  66 lines

  1. #! /bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides:          urandom
  4. # Required-Start:    $local_fs
  5. # Required-Stop:     $local_fs
  6. # Default-Start:     S
  7. # Default-Stop:      0 6
  8. # Short-Description: Save and restore random seed between restarts.
  9. # Description        This script saves the random seed between restarts.
  10. #                    It is called from the boot, halt and reboot scripts.
  11. ### END INIT INFO
  12.  
  13. [ -c /dev/urandom ] || exit 0
  14.  
  15. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  16. SAVEDFILE=/var/lib/urandom/random-seed
  17. POOLSIZE=512
  18. [ -f /proc/sys/kernel/random/poolsize ] && POOLSIZE="$(cat /proc/sys/kernel/random/poolsize)"
  19. . /lib/init/vars.sh
  20.  
  21. . /lib/lsb/init-functions
  22.  
  23. case "$1" in
  24.   start|"")
  25.     [ "$VERBOSE" = no ] || log_action_begin_msg "Initializing random number generator"
  26.     # Load and then save $POOLSIZE bytes,
  27.     # which is the size of the entropy pool
  28.     if [ -f "$SAVEDFILE" ]
  29.     then
  30.         # Handle locally increased pool size
  31.         SAVEDSIZE="$(find "$SAVEDFILE" -printf "%s")"
  32.         if [ "$SAVEDSIZE" -gt "$POOLSIZE" ]
  33.         then
  34.             [ -w /proc/sys/kernel/random/poolsize ] && echo $POOLSIZE > /proc/sys/kernel/random/poolsize
  35.             POOLSIZE=$SAVEDSIZE
  36.         fi
  37.         cat "$SAVEDFILE" >/dev/urandom
  38.     fi
  39.     rm -f $SAVEDFILE
  40.     umask 077
  41.     dd if=/dev/urandom of=$SAVEDFILE bs=$POOLSIZE count=1 >/dev/null 2>&1
  42.     ES=$?
  43.     umask 022
  44.     [ "$VERBOSE" = no ] || log_action_end_msg $ES
  45.     ;;
  46.   stop)
  47.     # Carry a random seed from shut-down to start-up;
  48.     # see documentation in linux/drivers/char/random.c
  49.     [ "$VERBOSE" = no ] || log_action_begin_msg "Saving random seed"
  50.     umask 077
  51.     dd if=/dev/urandom of=$SAVEDFILE bs=$POOLSIZE count=1 >/dev/null 2>&1
  52.     ES=$?
  53.     [ "$VERBOSE" = no ] || log_action_end_msg $ES
  54.     ;;
  55.   restart|reload|force-reload)
  56.     echo "Error: argument '$1' not supported" >&2
  57.     exit 3
  58.     ;;
  59.   *)
  60.     echo "Usage: urandom start|stop" >&2
  61.     exit 3
  62.     ;;
  63. esac
  64.  
  65. :
  66.